﻿package net.steam.easyjoboa.biz.impl;

import java.util.List;

import net.steam.easyjoboa.biz.ProclaimBiz;
import net.steam.easyjoboa.dao.ProclaimDao;
import net.steam.easyjoboa.entity.PageBean;
import net.steam.easyjoboa.entity.Proclaim;

public class ProclaimBizImpl implements ProclaimBiz {

	/**
	 * 添加公告，返回一个主键ID
	 */
	private ProclaimDao proclaimDao;
	
	public int addProclaim(Proclaim proclaim) {
		int key=0;
		try {
			key=proclaimDao.addEntity(proclaim);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return key;
	}
	public void setProclaimDao(ProclaimDao proclaimDao) {
		this.proclaimDao = proclaimDao;
	}
	
	/**
	 * 查询所有的公告
	 * 
	 * 返回一个Proclaim类型的集合
	 */
	public List<Proclaim> findAllProclaim(PageBean pb) {
		String hql="from Proclaim p order by p.createtime desc ";
		List<Proclaim> proclaims=proclaimDao.find(pb, hql);
		//如果没有公告就返回空
		if(proclaims.size()==0){
			return null;
		}else{
		return proclaims;
		}
	}
	
	/**
	 * 根据ID查找公告
	 * 显示公告的详情
	 */
	public Proclaim findProclaimById(int id) {
		try{
		return proclaimDao.findById(id);
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 更新公告
	 */
	public void updateProclaim(Proclaim proclaim) {
		
	}
	
	/**
	 * 员工查看有效公告
	 */
	public List<Proclaim> seeProclaim(PageBean pb) {
		String hql="from Proclaim p where p.status=0 order by p.createtime desc ";
		List<Proclaim> proclaims=proclaimDao.find(pb, hql);
		//如果没有公告就返回空
		if(proclaims.size()==0){
			return null;
		}else{
			return proclaims;
		}
	}

}
